const withSass = require('@zeit/next-sass');
const withImages = require('next-images');
const {baseUrl} = require('./build.config');
const withTM = require('next-transpile-modules');  // 可以用来配置 翻译node_modules里的东西

const nextConfig = {
  basePath: baseUrl, // router 的 basePath
  assetPrefix: baseUrl,
  exportPathMap: async function (
    defaultPathMap,
    {
      dev,  // 如果是true, 说明是开发环境， exportPathMap 会被当做 router
      dir,  // 项目绝对路径
      outDir,  // /out 目录的绝对路径，dev为true, 则该值为null
      distDir,  // .next 目录的绝对路径
      buildId  // 自增的 buildId 数字
    }
  ) {
    return {
      '/': {page: '/'},
    };
  },
  // 添加兼容配置
  webpack: function (config) {
    const originalEntry = config.entry;
    config.entry = async () => {
      const entries = await originalEntry();
      if (
        entries['main.js'] &&
        !entries['main.js'].includes('./core/polyfills.js')
      ) {
        entries['main.js'].unshift('./core/polyfills.js');
      }
      return entries;
    };
    return config
  },
  transpileModules: ['immer', 'swiper']
};


module.exports = withImages(
  withSass(
    withTM(nextConfig)
  )
);